{extend name="public/common-base" /}

{block name="style"}

<link rel="stylesheet" href="__STATIC__/index/css/jh.css" />

{/block}

{block name="main"}

<div class="in-public Shopping-Mall">


    <form name="cart2_form" id="cart2_form" method="post" style="margin-top:40px;">
        <div class="layout be-table fo-fa ma-bo-45">
            <div class="con-info">
                <div class="con-y-info ma-bo-35">
                    <h3>收货人信息<b>[<a href="javascript:void(0);" onclick="add_edit_address(0);">使用新地址</a>]</b></h3>

                    <div id="ajax_address"> <!--默认选中的地址-->
                        <div class="order-address-list address_current">
                            <table width="100%" cellspacing="0" cellpadding="0" border="1" class="address">
                                <tbody>
                                <tr>
                                    <td width="5%" class="default"><i></i></td>
                                    <td width="5%" class="co-red default">寄送至</td>
                                    <td width="5%" class="address_id"><input type="radio" data-province-id="4670" data-city-id="4874" data-district-id="4888" onclick="swidth_address(this);" name="address_id" value="829" checked="checked"></td>
                                    <td width="15%" class="consignee"><b>收货人:姚顺军</b></td>
                                    <td width="40%" class="address2"><span>地址:内蒙古自治区 赤峰市 元宝山区  12312312321</span></td>
                                    <td width="15%" class="mobile"><span>电话：13297151131</span></td>
                                    <td width="5%" class="wi100"><span>默认地址</span></td>
                                    <td width="5%" class="wi100"><span><a onclick="add_edit_address(829);">修改</a></span></td>
                                    <td><a onclick="del_address(829);"><div class="gwc-gb ma-ri-20"></div></a></td>
                                </tr>
                                </tbody>
                            </table>
                        </div>
                        <script>

                        </script>
                        <div class="order-address-list">
                            <table width="100%" cellspacing="0" cellpadding="0" border="1" class="address">
                                <tbody>
                                <tr>
                                    <td width="5%" class="default"><i></i></td>
                                    <td width="5%" class="co-red default">寄送至</td>
                                    <td width="5%" class="address_id"><input type="radio" data-province-id="5827" data-city-id="6476" data-district-id="6499" onclick="swidth_address(this);" name="address_id" value="832"></td>
                                    <td width="15%" class="consignee"><b>收货人:423</b></td>
                                    <td width="40%" class="address2"><span>地址:辽宁省 本溪市 明山区 明山街道 2342</span></td>
                                    <td width="15%" class="mobile"><span>电话：13297151131</span></td>
                                    <td width="5%" class="wi100"><span>&nbsp;&nbsp;</span></td>
                                    <td width="5%" class="wi100"><span><a onclick="add_edit_address(832);">修改</a></span></td>
                                    <td><a onclick="del_address(832);"><div class="gwc-gb ma-ri-20"></div></a></td>
                                </tr>
                                </tbody>
                            </table>
                        </div>
                        <div class="order-address-list">
                            <table width="100%" cellspacing="0" cellpadding="0" border="1" class="address">
                                <tbody>
                                <tr>
                                    <td width="5%" class="default"><i></i></td>
                                    <td width="5%" class="co-red default">寄送至</td>
                                    <td width="5%" class="address_id"><input type="radio" data-province-id="3102" data-city-id="3379" data-district-id="3381" onclick="swidth_address(this);" name="address_id" value="833"></td>
                                    <td width="15%" class="consignee"><b>收货人:4323</b></td>
                                    <td width="40%" class="address2"><span>地址:山西 阳泉市 城区 上站街道 2342</span></td>
                                    <td width="15%" class="mobile"><span>电话：13297151131</span></td>
                                    <td width="5%" class="wi100"><span>&nbsp;&nbsp;</span></td>
                                    <td width="5%" class="wi100"><span><a onclick="add_edit_address(833);">修改</a></span></td>
                                    <td><a onclick="del_address(833);"><div class="gwc-gb ma-ri-20"></div></a></td>
                                </tr>
                                </tbody>
                            </table>
                        </div>
                    </div>
                    <!--
                    <h3 style="margin-top:30px">自提点</h3>
                    <div id="ajax_pickup">
                    </div>
                    -->
                </div>
                <!--
                <div class="con-y-info ma-bo-35 con-h">
                    <h3>发票信息<em>(请谨慎选择发票抬头，订单出库后不能修改)</em></h3>

                    <div class="order-invoice-list">
                        <ul>
                            <li>
                                <div class="invoice-main fl"><label for="dw">发票抬头:</label></div>
                                <div class="invoice-sub fl">
                                    <label class="inv-label">
                                        <input class="officdw" type="text" name="invoice_title" placeholder="XXX单位 或 XX个人">
                                    </label>
                                </div>
                            </li>
                        </ul>
                    </div>
                    <p class="tips"><em>注意：</em>如果商品由第三方卖家销售，发票内容由其卖家决定，发票由卖家开具并寄出</p>
                </div>
                -->
            </div>
            <div class="sc-area">
                <div class="dt-order-area">
                    <div class="order-pro-list">
                        <!--商品列表-->
                        <div class="order-pro-list">
                            <div class="yxspy">
                                <div class="hv"></div>
                                <div class="bv">
                                    <table border="0" cellpadding="0" cellspacing="0">
                                        <thead>
                                        <tr>
                                            <th class="tr-pro">商品</th>

                                            <th class="tr-price">单价（元）</th>
                                            <!--/if condition="($user[discount] neq 1)"-->
                                            <!--<th class="tr-price">会员折扣价</th>-->
                                            <th class="tr-price"></th>
                                            <!--//if-->
                                            <th class="tr-quantity">数量</th>
                                            <th class="tr-subtotal">小计（元）</th>
                                        </tr>
                                        </thead>
                                    </table>
                                </div>
                            </div>
                            <div class="leiliste">
                                <table width="100%" border="0" cellpadding="0" cellspacing="0">
                                    <tbody>
                                    <?php foreach($goodsList as $k=>$v){?>
                                    <tr>
                                        <td class="tr-pro">
                                            <ul class="pro-area-2">
                                                <li>
                                                    <a target="_blank" href="<?=url('index/goods/goodsDetail',['goods_id'=>$v['goods_id']])?>"><img src="/<?=$v['original_img']?>" style="width:100px;height:100px;"></a>
                                                    <a title="<?=$v['goods_name']?>" target="_blank" href="<?=url('index/goods/goodsDetail',['goods_id'=>$v['goods_id']])?>" seed="item-name">
                                                        <?=$v['goods_name']?></a><?=$v['key_name']?>                                                                </li>
                                            </ul>
                                        </td>
                                        <!-- 预付订金商品的价格为空 -->
                                        <td class="tr-price te-al">¥<?=$v['shop_price']/$v['goods_num']?></td>
                                        <!--<//if condition="($user[discount] neq 1)">-->
                                        <!--<td class="tr-price te-al">¥2000.00</td>-->
                                        <td class="tr-price te-al"></td>
                                        <!--<///if>-->
                                        <td class="tr-quantity te-al"><?=$v['goods_num']?></td>
                                        <td rowspan="1" class="tr-subtotal te-al">
                                            <p><b>￥<?=$v['real_price']?></b></p>
                                        </td>
                                    </tr>
                                        <?php if($v['cart_id'] ==0){?>
                                            <input type="hidden" name="goods_id" value="<?=$v['goods_id']?>"/>
                                            <input type="hidden" name="spec_item_id" value="<?=$v['spec_price_goods_id']?>"/>
                                            <input type="hidden" name="goods_num" value="<?=$v['goods_num']?>"/>
                                        <?php }else{ ?>
                                            <input type="hidden" name="cart_id[]" value="<?=$v['cart_id']?>"/>
                                        <?php } ?>
                                    <?php }?>

                                    <tr>
                                        <td colspan="4"><span class="span_ored">优惠券:</span>
                                            <input type="radio" onclick="ajax_order_price();" value="1" checked="" name="couponTypeSelect" class="radio vam ma-ri-10">

                                            <select onchange="ajax_order_price();" class="vam ou-no" id="coupon_id" name="coupon_id">
                                                <option value="0">选择优惠券</option>
                                                <?php if(!empty($couponList)){ foreach($couponList as $k=>$v){?>
                                                    <option value="<?=$v['id']?>"><?=$v['name']?></option>
                                                <?php }}?>
                                            </select>

                                            <!--
                                            &nbsp;&nbsp;&nbsp;
                                            <input type="radio" onclick="ajax_order_price();" value="2" name="couponTypeSelect" class="radio vam ma-ri-10">
                                            <input type="text" placeholder="请输入优惠券代码" class="texter vam span-150 ma-ri-10 he18 li-he-18" name="couponCode">
                                            <input type="button" onclick="ajax_order_price();" value="使用" class="button-style-disabled-4 button-action-use-disabled te-al ou-no vam">
                                            -->
                                        </td>
                                        <td rowspan="1" class="tr-subtotal te-al">
                                            <p>-￥<b id="coupon_price">0</b></p>
                                        </td>
                                    </tr>

                                    <tr>
                                        <td colspan="4">
                                            <span class="span_ored">选择物流:</span>
                                            <select onchange="ajax_order_price();" class="vam ou-no" name="shipping_code">
                                                <?php if(!empty($shippingList)){ foreach($shippingList as $k=>$v){?>
                                                <option value="<?=$v['shipping_id']?>"><?=$v['shipping_name']?></option>
                                                <?php }}?>
                                            </select>
                                        </td>
                                        <td rowspan="1" class="tr-subtotal te-al">
                                            <p>￥<b id="shipping_price">30</b></p>
                                        </td>
                                    </tr>
                                    <!--<tr>-->
                                    <!--<td colspan="4"><span class="span_ored">商家活动：</span></td>-->
                                    <!--<td rowspan="1" class="tr-subtotal te-al">-->
                                    <!--<p>-￥<b id="store_order_prom_amount_">0</b></p>-->
                                    <!--</td>-->
                                    <!--</tr>-->
                                    <!--<tr>-->
                                    <!--<td colspan="4"><span class="span_ored">积分抵扣：</span></td>-->
                                    <!--<td rowspan="1" class="tr-subtotal te-al">-->
                                    <!--<p>-￥<b id="store_point_count_">0</b></p>-->
                                    <!--</td>-->
                                    <!--</tr>-->
                                    <!--<tr>-->
                                    <!--<td colspan="4"><span class="span_ored">余额抵扣：</span></td>-->
                                    <!--<td rowspan="1" class="tr-subtotal te-al">-->
                                    <!--<p>-￥<b id="store_balance_">0</b></p>-->
                                    <!--</td>-->
                                    <!--</tr>-->
                                    <!--<tr>-->
                                    <!--<td colspan="4"><span class="span_ored">店铺合计(含运费)：</span></td>-->
                                    <!--<td rowspan="1" class="tr-subtotal te-al">-->
                                    <!--<p>￥<b id="store_order_amount_">0</b></p>-->
                                    <!--</td>-->
                                    <!--</tr>-->
                                    <tr>
                                        <td colspan="5">
                                            <span class="span_ored">给卖家留言:</span>
                                            <input class="span_text texter tapassa" type="text" name="user_note" onkeyup="checkfilltextarea('.tapassa','50')">
                                            <span class="xianzd"><em id="zero">39</em>/50</span>
                                        </td>
                                    </tr>

                                    <tr>
                                        <td colspan="5">
                                            <span class="span_ored">您的可用积分:</span>
                                            <span class="xianzd"><em id="zero"><?=$member['integral']?></em></span>
                                        </td>
                                    </tr>
                                    </tbody>
                                </table>
                            </div>
                        </div>
                        <br>
                        <!--商品列表 end-->
                    </div>
                    <div class="order-pro-total">
                        <div class="fl wctmes">
                            <div class="syyouhui pa-to-15">
                                <div class="duoxuk">
                                    <label class="fo-fa-ta">使用优惠券:</label>&nbsp;&nbsp;注：优惠券每次只能使用一张，不可多张混合使用
                                </div>
                                <!--
                                <div class="byicd">
                                    <div class="zhiwfnka">
                                        <input style="display:none" type="password" name="paypwd">
                                        <table border="0" cellpadding="0" cellspacing="0">
                                        <tbody>
                                        <tr>
                                            <td>
                                                <label class="fo-fa-ta">余额支付:</label>
                                                <input type="text" id="user_money" name="user_money" class="texter vam span-150 ma-ri-10 he18 li-he-18" placeholder="请输入使用余额" onkeyup="this.value=/^\d+\.?\d{0,2}$/.test(this.value) ? this.value : ''">
                                                <input type="button" class="button-style-disabled-4 button-action-use-disabled te-al ou-no vam" value="使用" onclick="wield(this);"> 您的可用余额 ¥ 0.00                                                    </td>
                                        </tr>
                                        <tr>
                                            <td>
                                                <label class="fo-fa-ta">积分支付:</label>
                                                <input type="text" id="pay_points" name="pay_points" class="texter vam span-150 ma-ri-10 he18 li-he-18" placeholder="请输入使用积分" onkeyup="this.value=this.value.replace(/[^\d]/g,'')">

                                                <input type="button" class="button-style-disabled-4 button-action-use-disabled te-al ou-no vam" value="使用" onclick="wield(this);">
                                                100                                                        积分抵 1元 &nbsp;&nbsp; 您的可用积分 100 分
                                            </td>
                                        </tr>

                                        解决google浏览器识别text+password,自动填充已保存的账户密码
                                        <tr>
                                            <td>
                                                <label class="fo-fa-ta" for="paypwd">支付密码:</label>
                                                <input type="password" id="paypwd" name="paypwd" class="texter vam span-150 ma-ri-10 he18 li-he-18" placeholder="请输入支付密码">
                                                请先<a href="/index.php/home/User/paypwd.html" class="red">设置支付密码</a>
                                            </td>
                                        </tr>
                                        </tbody>
                                    </table>
                                    </div>
                                </div>
                                -->
                            </div>
                        </div>
                        <div class="fr wcnhy">
                            <div class="fzoubddv">
                                <table width="100%" border="0" cellpadding="0" cellspacing="0">
                                    <tbody>
                                    <tr>
                                        <td class="tal">商品总金额：</td>
                                        <td class="tar">&nbsp;¥&nbsp;
                                            <em id="totalFee"><?=$total['total_price']?></em>
                                        </td>
                                    </tr>
                                    <tr>
                                        <td class="tal">运费：</td>
                                        <td class="tar">&nbsp;¥&nbsp;
                                            <em id="postFee">0</em>
                                        </td>
                                    </tr>
                                    <tr>
                                        <td class="tal">使用优惠券：</td>
                                        <td class="tar">-&nbsp;¥&nbsp;
                                            <em><span id="couponFee">0</span> </em>
                                        </td>
                                    </tr>
                                    <tr>
                                        <td class="tal">需要积分：</td>
                                        <td class="tar">-&nbsp;¥&nbsp;
                                            <em><span id="pointsFee"><?=$total['total_integral']?></span> </em>
                                        </td>
                                    </tr>
                                    <tr>
                                        <td class="tal">订单优惠：</td>
                                        <td class="tar">-&nbsp;¥&nbsp;
                                            <em><span id="order_prom_amount">-0</span> </em>
                                        </td>
                                    </tr>

                                    </tbody>
                                </table>
                                <p class="yifje-order">
		                            	<span class="p-subtotal-price"> 应付金额：
		                                    <b class="total">¥</b>
		                                    <b class="total" id="payables"><?=$total['total_price']?></b>
		                                </span>
                                </p>
                            </div>
                        </div>
                    </div>
                </div>
                <div class="order-action-area te-al-ri">
                    <div class="woypdbe sc-acti-list">
                        <!--<span class="p-subtotal-price">应付总额：<b>¥<span class="vab" id="payableTotal">2276.00</span></b></span>-->
                        <a class="Sub-orders gwc-qjs" href="javascript:void(0);" onclick="submit_order();"><span>提交订单</span></a>
                    </div>
                </div>
            </div>
        </div>
    </form>

</div>
{/block}

{block name="js"}
<script>
    /**
     * 留言字数限制
     * tea ：要限制数字的class名
     * nums ：允许输入的最大值
     * zero ：输入时改变数值的ID
     */
    function checkfilltextarea(tea,nums){
        var len = $(tea).val().length;
        if(len > nums){
            $(tea).val($(tea).val().substring(0,nums));
        }
        var num = nums - len;
        num <= 0 ? $("#zero").text(0): $("#zero").text(num);  //防止出现负数
    }


    function add_edit_address(id=0) {
        if (id > 0) {
            var url = "/index.php/index/member/edit_address?scene=1&call_back=call_back_fun&id=" + id;
        }else {
            var url = "/index.php/index/member/add_address?scene=1&call_back=call_back_fun";

        }

        layer.open({
            type: 2,
            title: '添加收货地址',
            shadeClose: true,
            shade: 0.8,
            area: ['880px', '580px'],
            content: url,
        });

    }

    // 添加修改收货地址回调函数
    function call_back_fun(v) {
        layer.closeAll(); // 关闭窗口
        ajax_address(); // 刷新收货地址
    }

    // 获取订单价格
    function ajax_order_price() {
        $.ajax({
            type : "POST",
            url:"<?=url('index/cart/cart3')?>",//+tab,g
            data : $('#cart2_form').serialize()+"&act=order_price",// 你的formid
            dataType: "json",
            success: function(data){
                console.log(data);
                if(data.code != 200)
                {
                    //执行有误
                    layer.alert(data.msg, {icon: 2});
                    // 登录超时g
                    if(data.code == -1)
                        location.hrgef ="<?=url('index/login/login')?>";
                    return false;
                }
                // console.log(data);
                //$("#couponFee, #pointsFee, #order_prom_amount").css('display','none');

                $("#postFee").text(data.data.postFee); // 物流费
                $("#shipping_price").text(data.data.postFee); // 物流费
                if(data.data.couponFee == null){
                    $("#couponFee").text(0);// 优惠券
                }else{
                    $("#couponFee").text(data.data.couponFee);// 优惠券
                }
                $("#coupon_price").text(data.data.couponFee);// 优惠券

                $("#payables").text(data.data.payables);// 应付
                $('#order_prom_amount').text(data.data.couponFee);
//                layer.alert(data.msg, {icon: 2});
            }
        });
    }

    // 删除收货地址
    function del_address(id) {
        layer.confirm('确定要删除吗？', {
                btn: ['确定','取消'] //按钮
            }, function(index){
                layer.close(index);
                // 确定
                $.ajax({
                    url: "/index.php/index/member/del_address?id=" + id,
                    success: function (data) {

                        ajax_address(); // 刷新收货地址
                        //$('#ajax_pickup .order-address-list').removeClass('address_current');

                    }
                });
                layer.closeAll(); // 关闭窗口
            }, function(index){
                layer.close(index);
            }
        );
    }

    ajax_address();

    /*
    * ajax 获取当前用户的收货地址列表
    */
    function ajax_address() {
        $.ajax({
            url: "<?=url('index/Cart/ajaxAddress')?>",//+tab,
            success: function (data) {
                $("#ajax_address").html('');
                //console.log(data);
                $("#ajax_address").append(data);
                if (data != '') {
                    // 有收货地址列表 再计算价钱
                    ajax_order_price(); // 计算订单价钱
                }else{
                    add_edit_address(0);
                }
            }
        });
    }

    // 切换收货地址
    function swidth_address(obj) {
        var province_id = $(obj).attr('data-province-id');
        var city_id = $(obj).attr('data-city-id');
        var district_id = $(obj).attr('data-district-id');
        if (typeof($(obj).attr('data-province-id')) != 'undefined') {
            //ajax_pickup(province_id,city_id,district_id,0);
        }
        $(".order-address-list").removeClass('address_current');
        $(obj).parent().parent().parent().parent().parent().addClass('address_current');
        ajax_order_price(); // 计算订单价格
    }


    // 提交订单
    ajax_return_status = 1;
    function submit_order()
    {
        if(ajax_return_status == 0)
            return false;
        ajax_return_status = 0;
        $.ajax({
            type : "POST",
            url:"{:url('index/Cart/cart3')}",//+tab,
            data : $('#cart2_form').serialize()+"&act=submit_order",// 你的formid
            dataType: "json",
            success: function(data){

                if(data.code != 200)
                {
                    // alert(data.msg); //执行有误
                    layer.alert(data.msg, {icon: 2});
                    // 登录超时
                    if(data.code == -1)
                        location.hrgef ="<?=url('index/login/login')?>";

                    ajax_return_status = 1; // 上一次ajax 已经返回, 可以进行下一次 ajax请求

                    return false;
                }

                layer.msg('订单提交成功，正在跳转!', {
                    icon: 1,   // 成功图标
                    time: 2000 //2秒关闭（如果不配置，默认是3秒）
                }, function(){ // 关闭后执行的函数
                    location.href = "/index.php/index/cart/cart4?order_id="+data.data; // 跳转到结算页
                });
            }
        });
    }

</script>


<script>

</script>
{/block}